package vlms.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import vlms.bean.Movie;
import vlms.service.VLMSServiceProxy;

/**
 * Servlet implementation class UpdateMovie
 */
public class UpdateMovie extends HttpServlet {
	private static final long serialVersionUID = 1L;
	VLMSServiceProxy proxy = new VLMSServiceProxy();   
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UpdateMovie() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("how are you?");
		try
		{
		proxy.setEndpoint("http://localhost:8080/VLMS/services/VLMSService");
		String movieId=(String) request.getAttribute("movieId");
		
		System.out.println("in update" + movieId);
		Movie movie=proxy.retrieveMovieById(movieId);
		
		request.setAttribute("movie", movie);
		System.out.println("in update" + movie.getMoviename());
		
		RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/updateMovie.jsp");
		dispatcher.forward(request, response);
		
		}
		catch(Exception e)
		{
			request.setAttribute("message", "Please try again later");
			 
			 RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/adminHome.jsp");
			dispatcher.forward(request, response);
		}
	}

}
